package com.yuke.cloud.service.omc.service.impl;

import com.yuke.cloud.common.util.HttpAesUtil;
import com.yuke.cloud.service.omc.dao.OdsUserPointMapper;
import com.yuke.cloud.service.omc.dto.OdsPointsDto;
import com.yuke.cloud.service.omc.entity.OdsUserPoint;
import com.yuke.cloud.service.omc.service.OdsUserPointService;
import com.yuke.cloud.common.core.support.BaseService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * Created by zn on 2019/12/25.
 */
@Service
@Transactional
public class OdsUserPointServiceImpl extends BaseService<OdsUserPoint> implements OdsUserPointService {
    @Resource
    private OdsUserPointMapper odsUserPointMapper;

    @Override
     public OdsPointsDto getUserPoints(OdsUserPoint odsUserPoint) {

        OdsPointsDto odsPointsDto = new OdsPointsDto();

        if (odsUserPoint!=null&&odsUserPoint.getUserId()!=null){
            OdsUserPoint userPoint = selectOne(odsUserPoint);
            System.out.println(userPoint.toString());
            if (userPoint!=null){

                String pointBalance = HttpAesUtil.decode(userPoint.getPointBalance());
                //String amountBalance = HttpAesUtil.decode(userPoint.getAmountBalance());

                if (pointBalance == null &&Integer.parseInt(pointBalance)<0){
                    userPoint.setPointBalance("0");
                }
                if (userPoint.getAmountBalance() == null &&Integer.parseInt(userPoint.getAmountBalance())<0){
                    userPoint.setAmountBalance("0");
                }
                userPoint.setPointBalance(pointBalance);


                //OdsUserPoint表主键
                odsPointsDto.setUserPointId(userPoint.getUserPointId());
                //设置账户余额
                String amountBalance = userPoint.getAmountBalance();
                odsPointsDto.setAmountBalance(Integer.parseInt(amountBalance));
                //设置积分余额
                odsPointsDto.setPointBalance(Integer.parseInt(userPoint.getPointBalance()));

                odsPointsDto.setUserId(odsUserPoint.getUserId());
                odsPointsDto.setLoginName(userPoint.getLoginName());
                System.out.println("返回值odsPointsDto"+odsPointsDto);
            }

        }
        return odsPointsDto;


    }
}
